package observer;

import java.util.concurrent.CopyOnWriteArrayList;

public abstract class Observable {

	private CopyOnWriteArrayList<Observer> observers=new CopyOnWriteArrayList<Observer>();
	private String CMD;
	private Object response;
	
	
	public void add(Observer o)
	{
		observers.add(o);
	}
	
	public void remove(Observer o)
	{
		observers.remove(o);
	}
	
	public void setResponse(String CMD,Object response)
	{
		this.CMD=CMD;
		this.response=response;
	}
	
	public void notifyAllObservers(String CMD,Object response)
	{
		this.CMD=CMD;
		this.response=response;
		
		for(Observer o:observers)
		{
			o.update(CMD, response);
		}
		this.CMD="";
		this.response=null;
	}
	
	public void notifyAllObservers()
	{
		for(Observer o:observers)
		{
			o.update(this.CMD, this.response);
		}
	}
	
}
